/*
 * PacketTransmitter.cpp
 *
 *  Created on: 25 sept. 2009
 *      Author: CHETIER
 */

#include <iostream>
#include "PacketTransmitter.h"
#include "Config.h"

void PacketTransmitter::SendToServer(sf::IPAddress serverAdress, ClientInfo clientInfo)
{
	_serverAdress = serverAdress;
	_clientInfo = clientInfo;
	Launch();
}

void PacketTransmitter::Run()
{
	PacketInfo packetToSend;
	packetToSend << _clientInfo;

	sf::SocketUDP server;
	if (server.Send(packetToSend, _serverAdress, PORT_CLIENT_TO_SERVER) != sf::Socket::Done)
	{
		std::cout << "error while sending packet..." << std::endl;
		return ;//EXIT_FAILURE;
	}
//	std::cout << "packet sent :"
//		<< (_clientInfo.left ? " Left " : "-")
//		<<	(_clientInfo.right ? " Right " : "-")
//		<< (_clientInfo.up ? " Up ": "-")
//		<< (_clientInfo.down ? " Down " : "-")
//		<< std::endl;
}

PacketTransmitter::~PacketTransmitter()
{
	Wait();
}









